<template>
  <div class="text-right">
    <slot name="before"></slot>
    <el-button type="danger" size="mini" class="dis-lb" icon="el-icon-delete" @click="executeDelete">删除</el-button>
    <EditFormButton type="primary" icon="el-icon-add" size="mini"
                    class="dis-lb mar-rl-10px"
                    :url="url"
                    :fields="fields"
                    :form-data="formData" @editSuccess="editSuccess">新增</EditFormButton>
    <el-button type="info" icon="el-icon-search" size="small"  class="dis-lb"  @click="search">搜索</el-button>
    <slot name="after"></slot>
  </div>
</template>
<script >
  import http from "network/http";

  export default {
    props:{
      url: {
        type: String ,
        required: true
      },
      primaryIds:{
        type: Array ,
        required: true
      },
      fields: {
        type: Array ,
        required: true
      }
    },
    data(){
      return{
        formData:{}
      }
    },
    methods:{
      executeDelete(){
        if(this.primaryIds.length === 0){
          this.$message.warning("请选择数据")
          return
        }
        this.$confirm('确认删除选择的记录吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.handleRequest()
        }).catch(() => {

        });
      },
      handleRequest(){
        http.post(`${this.url}/deleteByIds` , {ids: this.primaryIds}).then(res=>{
          this.$emit("deleteSuccess",res)
        })
      },
      editSuccess(res){
        this.$emit("addSuccess",res)
      },
      search(){
        this.$emit("search")
      }
    }
  }
</script>
<style scoped>

</style>
